package HomeWork01;

/**
 * @author 李孟琦
 * @version V1.0
 * @ProjectName:IntelliJ IDEA
 * @PackageName: Demo01
 * @ClassName: 001
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2019/10/9 14:25
 * @Copyright 李孟琦版权所有
 */
public class Detail {  //商品详细信息类
    //属性：商品编号，商品名称，所属类别，商品数量（大于0），商品价格（大于0）
    private int num;
    private String name;
    private Commodity commodity;
    private int no;
    private int price;

    public Detail() {
    }

    public Detail(int num, String name, Commodity commodity, int no, int price) {
        this.num = num;
        this.name = name;
        this.commodity = commodity;
        this.setNo(no);
        this.setPrice(price);
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Commodity getCommodity() {
        return commodity;
    }

    public void setCommodity(Commodity commodity) {
        this.commodity = commodity;
    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        if (no < 0) {
            System.out.println("商品数量不可小于0,已默认设置商品数量为1");
            this.no = 1;
        } else {
            this.no = no;
        }
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        if (price < 0) {
            System.out.println("商品价格不可小于0,已默认设置商品价格为1");
            this.price = 1;
        } else {
            this.price = price;
        }
    }

    //方法：盘点的方法，描述商品信息。内容包括商品名称，商品数量，商品价格，现在商品总价以及所属类别信息
    public void print() {
        System.out.println("商品信息为:\n" + "商品名称为:" + name + ",商品数量为:" + no + ",商品价格为:" + price
                + "元" + ",目前商品总价为:" + (no * price) + "元" + ",所属类别为:" + commodity.getNo()+"\t"+commodity.getName());
    }

}
